﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Research.DynamicDataDisplay.Charts;
using Microsoft.Research.DynamicDataDisplay.Filters;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using System.Windows.Media;
using Microsoft.Research.DynamicDataDisplay.Common.Palettes;

namespace Microsoft.Research.DynamicDataDisplay.DirectX2D
{
    public static class Plotter2DExtensions
    {
        /// <summary>
        /// Adds one dimensional graph.
        /// </summary>
        /// <param name="pointSource">The point source.</param>
        /// <param name="lineColor">Color of the line.</param>
        /// <param name="lineThickness">The line thickness.</param>
        /// <param name="description">Description of data</param>
        /// <returns></returns>
        public static DirectXLineGraph AddDXLineGraph(this Plotter2D plotter, IPointDataSource pointSource, Color lineColor, double lineThickness,
            string description)
        {
            return AddDXLineGraph(plotter, pointSource, new Pen(new SolidColorBrush(lineColor), lineThickness), new PenDescription(description));
        }

        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public static DirectXLineGraph AddDXLineGraph(this Plotter2D plotter, IPointDataSource pointSource, Pen linePen, Description description)
        {
            if (pointSource == null)
                throw new ArgumentNullException("pointSource");
            if (linePen == null)
                throw new ArgumentNullException("linePen");
            
            

            //LineGraph graph = new LineGraph
            //{
            //    DataSource = pointSource,
            //    LinePen = linePen
            //};
            DirectXLineGraph graph = new DirectXLineGraph();            
            graph.LinePen = linePen;            
            if (description != null)
            {
                NewLegend.SetDescription(graph, description.Brief);
                graph.Description = description;
            }
            //plotter.Children.Add(graph);
            graph.AddToPlotter(plotter);
            graph.DataSource = pointSource;
             //graph.Filters.Add(new InclinationFilter());
            graph.Filters.Add(new FrequencyFilter());
            //graph.RemoveFromPlotter();
            
            return graph;
        }

        public static DirectXWorkingColorMap AddDXColorMap(this Plotter2D plotter, IDataSource2D<double> dataSource, IPalette palette)
        {
            if (dataSource == null) throw new ArgumentNullException("dataSource");

            DirectXWorkingColorMap colorMap = new DirectXWorkingColorMap()
            {
                DataSource = dataSource,
                Palette = palette
            };

            plotter.Children.Add(colorMap);

            return colorMap;
        }
    }
}
